package com.fancy.learncenter.ui.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.fancy.learncenter.R;
import com.fancy.learncenter.bean.BaseBean;
import com.fancy.learncenter.bean.CartoonTeacherReportDataBean;
import com.fancy.learncenter.net.CustomNetCallBack;
import com.fancy.learncenter.net.CustomNetSubscriber;
import com.fancy.learncenter.net.HttpMehtod;
import com.fancy.learncenter.ui.adapter.CartoonTeacherClassReportContentAdapter;
import com.fancy.learncenter.ui.adapter.CartoonTeacherClassReportSutendAdapter;
import com.fancy.learncenter.ui.adapter.ScrollablePanelAdapter;
import com.fancy.learncenter.utils.NetUtil;
import com.fancy.learncenter.utils.Utils;
import com.kelin.scrollablepanel.library.ScrollablePanel;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import okhttp3.ResponseBody;
import retrofit2.Response;

import static com.fancy.learncenter.ui.activity.CartoonTeacherClassDetailActivity.CLASS_ID_KEY;

/**
 * A simple {@link Fragment} subclass.
 */
public class CartoonTeacherClassWeekReportFragment extends Fragment {


    @Bind(R.id.scrolll_panel)
    ScrollablePanel scrolllPanel;

    public CartoonTeacherClassWeekReportFragment() {
        // Required empty public constructor
    }

    public static CartoonTeacherClassWeekReportFragment newInstance(String classID) {

        Bundle args = new Bundle();
        args.putString(CLASS_ID_KEY, classID);

        CartoonTeacherClassWeekReportFragment fragment = new CartoonTeacherClassWeekReportFragment();
        fragment.setArguments(args);

        return fragment;
    }

    String classID;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if (getArguments() != null) {
            classID = getArguments().getString(CLASS_ID_KEY);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_cartoon_teacher_class_total_report, container, false);
        ButterKnife.bind(this, view);


        getTeacherClassList();
        return view;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }


//    private int horizonNum = 5;
//    private int verticalNum = 50;

    private void generateTestData(ScrollablePanelAdapter scrollablePanelAdapter, List<CartoonTeacherReportDataBean.ResultBean.StatisticListBean> itemDatas) {
        scrollablePanelAdapter.setRoomInfoList(itemDatas);


        List<String> horizontalInfoList = new ArrayList<>();
        horizontalInfoList.add("跟读（道)");
        horizontalInfoList.add("跟读（道)");
        horizontalInfoList.add("拓展训练（道)");
        horizontalInfoList.add("绘本阅读（本)");
        horizontalInfoList.add("错题（道)");
        scrollablePanelAdapter.setHorizontalInfoList(horizontalInfoList);


        List<List<String>> ordersList = new ArrayList<>();
        for (int i = 0; i < itemDatas.size(); i++) {
            List<String> orderInfoList = new ArrayList<>();

            orderInfoList.add(itemDatas.get(i).getDailyCount());
            orderInfoList.add(itemDatas.get(i).getExpandCount());
            orderInfoList.add(itemDatas.get(i).getPictureCount());
            orderInfoList.add(itemDatas.get(i).getErrorCount());

            orderInfoList.add("占位" + i);
//            for (int j = 0; j < horizonNum; j++) {
//            }
//
            ordersList.add(orderInfoList);
        }

        scrollablePanelAdapter.setOrdersList(ordersList);
    }


    private void getTeacherClassList() {
        Map<String, Object> map = new HashMap<>();
        map.put("classId", classID);
        map.put("statisticType", "1");

        HttpMehtod.getInstance().reportHomeWork(map, new CustomNetSubscriber(getActivity(), true) {
            @Override
            public void onNext(Response<ResponseBody> responseBodyResponse) {


                BaseBean<CartoonTeacherReportDataBean> baseBean = Utils.fromJsonObject(NetUtil.getResResult(responseBodyResponse), CartoonTeacherReportDataBean.class);
                CustomNetCallBack callBack = new CustomNetCallBack(getContext(), baseBean);
                callBack.setCallBack(new CustomNetCallBack.NetCallBack<CartoonTeacherReportDataBean>() {
                    @Override
                    public void success(CartoonTeacherReportDataBean dataBean) {

                        List<CartoonTeacherReportDataBean.ResultBean.StatisticListBean> itemDatas = dataBean.getResult().getStatisticList();

                        ScrollablePanelAdapter scrollablePanelAdapter = new ScrollablePanelAdapter();
                        generateTestData(scrollablePanelAdapter, itemDatas);
                        scrolllPanel.setPanelAdapter(scrollablePanelAdapter);

                    }

                    @Override
                    public void fail(String errorCode) {


                    }
                }).dealData();
            }

        });
    }

}
